<template>
  <div class="table-reserve">
    <vab-query-form>
      <vab-query-form-left-panel>
        <el-button icon="el-icon-plus" type="primary" @click="handleAdd(0,'')" >
          入住预定
        </el-button>


      </vab-query-form-left-panel>
      <vab-query-form-right-panel>


        <el-form
          ref="form"
          size="mini"
          :model="formInline"
          :inline="true"
          @submit.native.prevent
        >
          <el-form-item    >
            <el-select
              @change="changes"
              v-model="formInline.institutionNumber"
              placeholder="机构名称">
              <el-option

                v-for="item in options"
                :key="item.institutionNumber"
                :label="item.institutionName"
                :value="item.institutionNumber">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-input v-model="organ.name" placeholder="老人姓名" />
          </el-form-item>
          <el-form-item>
            <el-button

              icon="el-icon-search"
              type="primary"
              native-type="button"
              @click="search"
            >
              查询
            </el-button>
          </el-form-item>
        </el-form>

      </vab-query-form-right-panel>
      <el-table
        ref="tableSort"

        :data="list"
        style="float: left"
        v-loading="listLoading"

      >

        <el-table-column
          show-overflow-tooltip
          label="预定人姓名"
          width="150px"
          prop="bookerName"
        ></el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="contactNumber"
          label="预定人联系电话"
          width="150px"
        ></el-table-column>
        <el-table-column
          width="150px"
          show-overflow-tooltip
          prop="relationshipName"
          label="预定人与老人关系"

        ></el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="elderlyName"
          label="老人姓名"

        ></el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="elderlyCardNo"
          label="证件号"

        ></el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="elderlyBirth"
          label="出生日期"

        ></el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="elderlyGenderName"
          label="老人性别"

        ></el-table-column>

        <el-table-column
          show-overflow-tooltip
          prop="elderlyBirth"
          label="计划入住时间"
          width="150px"
        ></el-table-column>

        <el-table-column label="状态" >
          <template slot-scope="scope">
                <span v-if="scope.row.status==0">

             <el-tag >预定中</el-tag>
                </span>
            <span v-if="scope.row.status==1">     <el-tag type="success">转入住</el-tag></span>
            <span v-if="scope.row.status==2">     <el-tag type="danger">超时未入住</el-tag></span>
            <span v-if="scope.row.status==3">     <el-tag type="warning">退订</el-tag></span>
          </template>
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="remark"
          label="备注"

        ></el-table-column>
        <el-table-column
          show-overflow-tooltip
          label="操作"
          width="300px"
          fixed="right"
        >
          <template slot-scope="scope">
            <el-button type="text"  v-if="scope.row.status!=3 && scope.row.status!=1"  @click="handlemove(scope.row.id,scope.row)">转入住 <i class="el-icon-edit"></i></el-button>
            <el-button type="text"   v-if="scope.row.status!=3 && scope.row.status!=1"  @click="handleAdd(scope.row.id,scope.row)">修改 <i class="el-icon-edit"></i></el-button>
            <el-button type="text"  @click="handleInfo(scope.row.id,scope.row)">详情<i class="el-icon-tickets"></i></el-button>

            <el-button type="text"   @click="back(scope.row.id,scope.row)"  v-if="scope.row.status!=3 && scope.row.status!=1">退订<i class="el-icon-sold-out"></i></el-button>

          </template>
        </el-table-column>

      </el-table>

    </vab-query-form>
    <el-pagination
      :background="background"


      :total="total"
      :page-size="queryForm.limit"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
    ></el-pagination>
    <el-dialog
      :title="title"
      :visible.sync="dialogFormVisible"
      destroy-on-close

    >
      <el-container>

        <el-main>
          <el-form ref="form"     :model="form"  :rules="rules"  >
          <el-row>
            <el-col :span="10">
              <el-form-item label="机构名称" prop="institutionNumber" >

                <el-select
                  v-if=!isdisabled
                  v-model="form.institutionNumber"
                  @change="change"
                  style="width: 100%"
                  placeholder="机构名称">
                  <el-option
                    v-for="item in options"
                    :key="item.institutionNumber"
                    :label="item.institutionName"
                    :value="item.institutionNumber">
                  </el-option>
                </el-select>
                <span :v-if=isdisabled>
             {{form.institutionName}}
          </span>
              </el-form-item>

            </el-col>

            <el-col :span="10" style="margin-left: 20px">

              <el-form-item label="预定人姓名" prop="bookerName" >
                <el-input v-model="form.bookerName"    style="width: 100%;" @blur="phone"></el-input>

              </el-form-item>
            </el-col>
            <el-col :span="10">
              <el-form-item label="老人姓名" prop="elderlyName">
                <el-input v-model="form.elderlyName"  style="width: 100%" ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="10" style="margin-left: 20px">
              <el-form-item label="预定人联系电话" prop="contactNumber"   >
                <el-input  v-model="form.contactNumber"  style="width: 100%" @blur="phone"></el-input>
              </el-form-item>

            </el-col>
          </el-row>
          <el-row>
            <el-col :span="10">
              <el-form-item label="预定人与老人关系" required>
                <el-select v-model="relationship" style="width: 100%" placeholder="请选择">
                  <el-option
                    v-for="item in relationships"
                    :key="item.dcNo"
                    :label="item.name"
                    :value="item.dcNo">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="10" style="margin-left: 20px">
              <el-form-item label="老人身份证" prop="elderlyCardNo">
                <el-input  v-model="form.elderlyCardNo"  onkeyup="this.value=this.value.replace(/[^\X0-9]/g, '')" style="width: 100%" ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="10" >
              <el-form-item label="老人出生日期" prop="elderlyBirth">

                <el-date-picker
                  v-model=" form.elderlyBirth"
                  type="date"
                  style="width: 100%"
                  value-format="yyyy-MM-dd"
                  placeholder="出生日期">
                </el-date-picker>

              </el-form-item>
            </el-col>
            <el-col :span="10" style="margin-left: 20px">
              <el-form-item label="计划入住时间" prop="plannedCheckInTime" >
                <el-date-picker
                  v-model="form.plannedCheckInTime"
                  type="date"
                  style="width: 100%"
                  value-format="yyyy-MM-dd"
                  placeholder="计划入住时间">
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="10">

              <el-form-item label="楼宇名称"  required>
                <el-select v-model="value2"   placeholder="楼宇名称"   style="width:100% "  @change="changestor">
                  <el-option
                    v-for="item in option"
                    :key="item.number"
                    :disabled="item.disabled==1"
                    :label="item.name"
                    :value="item.number">
                  </el-option>
                </el-select>


              </el-form-item>
            </el-col>

            <el-col :span="10" style="margin-left: 20px">
              <el-form-item label="房间号"  required>
                <el-select v-model="value3"   placeholder="房间号"   style="width:100% "  @change="changesroom">
                  <el-option
                    v-for="item in room"
                    :key="item.id"

                    :label="item.roomCode"
                    :value="item.id">
                    <span style="width: 33%; float: left">{{ item.roomCode }}</span>
                    <span style=" width: 33%;float: left; color: #8492a6; font-size: 13px">{{ item.unit }}单元</span>
                    <span style="width: 33%; float: right;color: #8492a6; font-size: 13px">{{ item.floor }}楼</span>
                  </el-option>
                </el-select>

              </el-form-item>
            </el-col>
            <el-col :span="10">

              <el-form-item label="床位号"  required>
                <el-select v-model="value4" placeholder="床位号" @change="changebed"   style="width:100%">
                  <el-option
                    :disabled="item.disableds"
                    v-for="item in bed"
                    :key="item.bedCode"
                    :label="item.bedCode"
                    :value="item.bedCode">
                    <span style="float: left">{{ item.bedCode }}</span>
                    <span style="float: right; color: #8492a6; font-size: 13px">{{ item.statusName }}</span>
                  </el-option>
                </el-select>


              </el-form-item>
            </el-col>
          </el-row>
          <el-form-item label="性别"  required>
            <template>
              <el-radio v-model="radio" :label=1>男</el-radio>
              <el-radio v-model="radio" :label=0>女</el-radio>
            </template>
          </el-form-item>
          <el-form-item label="备注信息" >
            <el-input  type="textarea" v-model="form.remark"  ></el-input>
          </el-form-item>


        </el-form>
        </el-main>




        <el-aside :width=scrollerWidth>
          <el-header style="text-align: center; font-size: 14px;height: 30px">

            <span>咨询记录</span>
          </el-header>
          <el-table
            v-if="!isdisabled"
            class="active"
            ref="singleTable"
            :data="tableData"
            highlight-current-row
            @row-click="handleRowClick"
            @current-change="handleCurrent"
            style="width: 100%;cursor:pointer">
            <el-table-column
              property="consultantName"
              label="咨询人姓名"
              width="120"
            >
            </el-table-column>

            <el-table-column
              property="elderlyName"
              label="老人姓名"
              width="120px"
             >
            </el-table-column>

            <el-table-column

              property="consultantRelationshipName"
              label="咨询人与老人关系"
              width="200">
            </el-table-column>
            <el-table-column

              property="consultantContactNumber"
              label="联系方式"
              width="200">
            </el-table-column>
            <el-table-column
              property="elderlyGenderName"
              label="性别"
             >
            </el-table-column>
            <el-table-column
              property="elderlySelfCareName"
              label="自理情况"
              >
            </el-table-column>
          </el-table>
          <div slot="footer" class="dialog-footer">
            <el-button @click="closes">取 消</el-button>
            <el-button type="primary" @click="saveadd()">确 定</el-button>
          </div>




        </el-aside>

      </el-container>

      <div slot="footer" class="dialog-footer">
        <el-button @click="close">取 消</el-button>
        <el-button type="primary"  @click="save">确 定</el-button>
      </div>

    </el-dialog>
    <reserveinfo ref="info"></reserveinfo>
<!--    <el-dialog-->
<!--      title="咨询接待记录信息"-->
<!--      :visible.sync="diaphone"-->
<!--        width="750px"-->
<!--      destroy-on-close-->
<!--    >-->
<!--      <el-table-->

<!--         class="active"-->
<!--        ref="singleTable"-->
<!--        :data="tableData"-->
<!--        highlight-current-row-->
<!--        @current-change="handleCurrent"-->
<!--        style="width: 100%;cursor:pointer">-->
<!--        <el-table-column-->
<!--          property="consultantName"-->
<!--          label="咨询人姓名"-->
<!--          width="120">-->
<!--        </el-table-column>-->

<!--        <el-table-column-->
<!--          property="elderlyName"-->
<!--          label="老人姓名"-->
<!--          width="120">-->
<!--        </el-table-column>-->

<!--        <el-table-column-->

<!--        property="consultantRelationshipName"-->
<!--        label="咨询人与老人关系"-->
<!--        width="200">-->
<!--      </el-table-column>-->
<!--        <el-table-column-->
<!--        property="elderlyGenderName"-->
<!--        label="性别"-->
<!--        width="120">-->
<!--      </el-table-column>-->
<!--        <el-table-column-->
<!--          property="elderlySelfCareName"-->
<!--          label="自理情况"-->
<!--          width="120">-->
<!--        </el-table-column>-->
<!--      </el-table>-->
<!--      <div slot="footer" class="dialog-footer">-->
<!--        <el-button @click="closes">取 消</el-button>-->
<!--        <el-button type="primary" @click="saveadd()">确 定</el-button>-->
<!--      </div>-->

<!--    </el-dialog>-->
  </div>


</template>

<script>

    import { searchstor,searchelderlyfile} from "@/api/reserve"
    import { searchrecordCode } from "@/api/reserve"
    import {searchroom} from "../../api/reserve";
    import {searchbed} from "../../api/reserve";
    import {add} from "../../api/reserve";
    import {search} from "../../api/reserve";
    import {back} from "../../api/reserve";
    import {revise} from "../../api/reserve";
    import reserveinfo  from "./compontent/reserveinfo";
    import { isIdentityId } from "@/api/validate"
    export default {
        name: "Reserve",
      components: {reserveinfo},

        data(){
            var checkIdentitytionId  = (rule, value, callback) => {
                var errorMsg = isIdentityId(value);
                if (errorMsg != "") {
                    callback(new Error(errorMsg));
                }else {

                    this.getBirthdayFromIdCard(value)
                    this.getradio(value)
                    callback();
                }

            }
                    return{
                tableData: [],
                currentRow: null,

          flage:1,
                organ:{
                    name:"",
                },

                        scrollerWidth:'40%',

                        formInline: {
                            institutionNumber:"",
                        },
                dictionary:"",
                dialogFormVisible:false,
                isdisabled:false,
                background:true,
                diaphone:false,
                id:0,
                total:0,
                list:[],
                listLoading:false,
                title:"填写预定信息",
                options:[],
                value:"",
                option:[],
                value3:"",
                room:[],
                value2:"",
                bed:[],
                value4:"",
                radio:1,
                // institutionNumber:"",
                number:"",
              // elderlyBirth:"",
              //   plannedCheckInTime:"",

                relationship:"",
                relationships:{

                },
                queryForm: {
                    currPageNo: 1,
                    limit: 8,
                    elderlyName:"",

                },
                rules: {
                    institutionNumber: [
                        { required: true, message: '机构名称', trigger: 'change' },

                    ],
                    elderlyCardNo: [
                        {required: true, validator: checkIdentitytionId , trigger: "blur" }
                    ],
                    bookerName:[
                        {required: true, message: '预定人姓名', trigger: "blur" }
                    ],
                    elderlyName:[
                        {required: true, message: '老人姓名', trigger: "blur" }
                    ],
                    contactNumber:[
                        {required: true, message: '预定人联系电话', trigger: "blur" }
                    ],
                    elderlyBirth:[
                        {required: true, message: '出生日期', trigger: "change" }
                    ],
                    plannedCheckInTime:[
                        {required: true, message: '计划入住时间', trigger: "change" }
                    ],
                },

                form:{
                    receptionCode:"",//接待编号
                    bookerName:"",//预定人姓名
                    elderlyName:"",//老人姓名
                    contactNumber:"",//预定人联系电话
                    elderlyCardNo:"",//老人身份证号
                    elderlyGender:"",//老人性别
                    elderlyBirth:"",//老人出生日期
                    institutionNumber:"",//所属机构编号
                    plannedCheckInTime:"",//计划入住时间
                    relationship:"",//预定人与老人关系
                    remark:"",//备注
                    buildingNumber:"",//楼宇编号
                    unit:"",//楼宇单元
                    floor:"",//楼宇楼层
                    roomNumber:"",//房间编号
                    bedNumber:""//床位编号

                },

            }

        },
        created(){

            this.dictionary=JSON.parse(localStorage.getItem("dictionary"))
            for(var i=0;i<this.dictionary.length;i++) {
                if (this.dictionary[i].mark == "relationship") {
                    this.relationships = (this.dictionary[i].childs)
                }
            }



            setTimeout(() => {

                this.formInline.institutionNumber=localStorage.getItem("institutionNumber")
                this.queryForm.institutionNumber=localStorage.getItem("institutionNumber")
                this.options= JSON.parse(localStorage.getItem("childinstitutionNumber"));
              this.search()
            }, 1000);

            console.log(JSON.parse(localStorage.getItem("childinstitutionNumber")))

        },

        methods:{

            getBirthdayFromIdCard(idCard) {
                var birthday = "";
                if(idCard != null && idCard != ""){
                    if(idCard.length == 15){
                        birthday = "19"+idCard.substr(6,6);
                    } else if(idCard.length == 18){
                        birthday = idCard.substr(6,8);
                    }

                    birthday = birthday.replace(/(.{4})(.{2})/,"$1-$2-");
                }

                this.form.elderlyBirth=birthday
            },
            getradio(idCard){
                if (parseInt(idCard.substr(16, 1)) % 2 == 1) {
                    this.radio=1

                } else {
                      this.radio=0

                }
            },
            handleCurrent(val) {

                this.flage=1
                this.currentRow = val;
                if(this.currentRow){
                    this.relationship=this.currentRow.consultantRelationship
                    this.form.receptionCode=this.currentRow.code
                    this.form.elderlyName=this.currentRow.elderlyName
                    this.form.bookerName=this.currentRow.consultantName
                    this.form.contactNumber=this.currentRow.consultantContactNumber
                }

            },

            handleRowClick(){
               this.flage++
                console.log(this.flage)
                if(this.flage===3){

                    this.setCurrent()
                    this.flage=1
                }
            },
            setCurrent(row) {
                this.relationship=1
                this.form.receptionCode=""
                this.form.elderlyName=""
                this.form.bookerName=""
                this.form.contactNumber=""
                this.$refs.singleTable.setCurrentRow(row);
                console.log(this.form)

            },
            phone(){

               if(this.form.contactNumber!=="" && (/^1(3|4|5|6|7|8|9)\d{9}$/.test(this.form.contactNumber))){
                   let consultant=this.form.contactNumber
                   searchrecordCode({consultant}).then(res =>{
                       console.log(res.data)
                        this.tableData=res.data


                   })

                   this.diaphone=true
               }else {
                   if(this.form.bookerName){
                       let consultant=this.form.bookerName
                       searchrecordCode({consultant}).then(res =>{
                           console.log(res.data)
                           this.tableData=res.data


                       })
                   }

               }



            },

            closes(){
                this.diaphone=false
            },
            saveadd(){
             console.log(this.currentRow)
                   if(this.currentRow){
                       this.relationship=this.currentRow.consultantRelationship
                       this.form.receptionCode=this.currentRow.code
                       this.form.elderlyName=this.currentRow.elderlyName
                       this.form.bookerName=this.currentRow.consultantName
                       this.form.contactNumber=this.currentRow.consultantContactNumber
                   }

                this.diaphone=false
            },
            changebed(value){

                console.log(value)
                let obj = {};
                obj = this.bed.find((item)=>{
                    return item.bedCode === value;
                });
                let getName = ''
                getName = obj.statusName;
                console.log(getName)

                if(getName=='已预订'){
                    this.$baseConfirm("此床位已预订，你确定要继续使用吗？", null, async () => {

                    });

                }

            },
            handlemove(id,row){


                let elderlyCondition=row.elderlyCardNo
                searchelderlyfile({elderlyCondition}).then(res =>{

                    if(res.data){
                         if(res.data.length==1){

                             this.$router.push({ name:'movesets', params: { id: 1,flage:1,name:row.elderlyName,institutionName:row.institutionName,destineCode:row.identify,receptionCode:row.receptionCode,data:res.data} })
                         }

                    }else {

                        this.$router.push({ name:'movesets', params: { id: 1,flage:0,name:row.elderlyName,institutionName:row.institutionName,destineCode:row.identify,bookerName:row.bookerName,contactNumber:row.contactNumber,relationship:row.relationship,elderlyGender:row.elderlyGender,
                                elderlyCardNo:row.elderlyCardNo,elderlyBirth:row.elderlyBirth,receptionCode:row.receptionCode} })
                    }


                })

            },
          handleInfo(index,row) {

            this.$refs["info"].showEdit(row);
          },
            handleAdd(id,data) {

                this.id = id
                console.log(data)



                this.dialogFormVisible=true
                if(this.id>0){
                    this.title="修改预订信息"
                    this.scrollerWidth='0'
                    this.isdisabled = true
                    this.relationship = data.relationship
                    // this.elderlyBirth = data.elderlyBirth
                    // this.plannedCheckInTime = data.plannedCheckInTime

                    this.room=""
                    this.value3=""
                    this.value2 = data.buildingNumber
                    this.value4 = data.bedNumber
                    let institutionNumber=data.institutionNumber
                    let number=data.buildingNumber
                    let roomCode=data.roomNumber
                    let unit=data.unit
                    let floor=data.floor
                    searchstor({institutionNumber}).then(res =>{
                        console.log(res)
                        this.option=res.data


                    })
                    searchroom({number,institutionNumber}).then(res =>{
                        console.log(res.data.data)
                        this.room=res.data.data
                        for(var i=0;res.data.data;i++){
                             if(data.roomNumber==res.data.data[i].roomCode){

                                     console.log(res.data.data[i].id)
                                 this.value3=res.data.data[i].id
                             }else if(this.value3){

                                 return false
                             }
                        }


                    })
                    searchbed({number,institutionNumber,roomCode,unit,floor}).then(res =>{
                        console.log(res)
                        if(res.data.data){
                            this.form.floor=res.data.data[0].floor
                            this.form.unit=res.data.data[0].unit
                            for(var i=0;i<res.data.data.length;i++){
                                if(res.data.data[i].status==2){
                                    res.data.data[i].disableds=true

                                }else {
                                    res.data.data[i].disableds=false


                                }
                            }
                        }

                        this.bed=res.data.data

                    })
                     this.form={
                        ...data
                     }



                }else {

                    console.log(data)
                    let institutionNumber=localStorage.getItem("institutionNumber")


                    searchstor({institutionNumber}).then(res =>{
                        console.log(res)
                        this.option=res.data
                        for(var i=0;i<res.data.length;i++){
                            this.value2=res.data[i].number

                        }
                        let  number=this.value2
                        let limit=9999
                        searchroom({number,institutionNumber,limit}).then(res =>{
                            console.log(res)
                            this.room=res.data.data
                            for(var i=0;i<res.data.data.length;i++){
                                this.value3=res.data.data[i].id
                                var  unit=res.data.data[i].unit
                                var  floor=res.data.data[i].floor

                            }
                            let obj = {};
                            obj = this.room.find((item)=>{
                                return item.id === this.value3;

                            });
                            console.log(obj)
                            let getName = ''
                            getName = obj.roomCode;
                            console.log()
                            let roomCode=getName
                            searchbed({number,institutionNumber,roomCode,unit,floor}).then(res =>{
                                console.log(res)
                                if(res.data.data){
                                    for(var i=0;i<res.data.data.length;i++){
                                        if(res.data.data[i].status==2){
                                            res.data.data[i].disableds=true

                                        }else {
                                            res.data.data[i].disableds=false
                                            this.value4=res.data.data[i].bedCode

                                        }


                                    }

                                    this.bed=res.data.data
                                }


                            })
                        })

                    })




                    this.isdisabled = false
                    this.tableData=[]
                    this.title="填写预定信息"
                    this.scrollerWidth=40+'%'
                    this.form.institutionName=""
                    this.form.institutionNumber=localStorage.getItem("institutionNumber")
                    this.buildingNumber=""
                    // this.value2= ""
                    // this.room=[]
                    this.bed=[]
                    // this.option=[]
                    // this.value3=""
                    this.value4= ""
                    this.radio=1
                    this.relationship=1
                    this.form.bookerName=""
                    this.form.elderlyName=""
                    this.form.contactNumber=""
                    this.form.elderlyCardNo=""
                    this.form.plannedCheckInTime=""
                    this.form.elderlyBirth=""
                    this.form.remark=""

                }
                this.$nextTick(() => {
                    this.$refs['form'].clearValidate();
                })
            },
            handleSizeChange(val) {
                this.queryForm.limit = val;
                this.search();
            },
            handleCurrentChange(val) {
                this.queryForm.currPageNo = val;
                this.search();
            },
            change(value){
                 this.value2=""
                 this.value3=""
                  this.value4=""
                  this.room=[]
                  this.bed=[]
                let institutionNumber=value
              this.institutionNumber=value
                searchstor({institutionNumber}).then(res =>{
                    console.log(res)
                      this.option=res.data


                })

            },
            changes(value){
                this.queryForm.currPageNo=1
                this.queryForm.institutionNumber=value


            },
            changestor(value){
                this.value3=""
                this.value4=""
                this.bed=[]
                  let institutionNumber=this.institutionNumber
                   let number=value
                    this.number=value
                let limit=9999
                searchroom({number,institutionNumber,limit}).then(res =>{
                    console.log(res)
                     this.room=res.data.data


                })

            },
            back(id,row){
                console.log(row)
                if (row.id) {
                    let identify=row.identify
                    this.$baseConfirm("你确定要退订吗？", null, async () => {
                        const {code, msg } = await back(({identify}));
                        if(code==200){

                            this.$baseMessage(msg, "success");
                            this.search();
                        }else {

                        }
                    });
                }
                // back().then(res =>{
                //     console.log(res)
                //     this.room=res.data.data
                //
                //
                // })
            },
            changesroom(value){
                 this.value4=""
                this.bed=[]
                let institutionNumber=this.institutionNumber
                let number=this.value2

                let obj = {};
                obj = this.room.find((item)=>{
                    return item.id === value;

                });
                console.log(obj)
                let getName = ''
                getName = obj.roomCode;
                console.log()
                let roomCode=getName
                 let unit=obj.unit
                 let floor=obj.floor
                searchbed({number,institutionNumber,roomCode,unit,floor}).then(res =>{
                    console.log(res)
                    for(var i=0;i<res.data.data.length;i++){
                        if(res.data.data[i].status==2){
                            res.data.data[i].disableds=true

                        }else {
                            res.data.data[i].disableds=false


                        }
                    }
                    if(res.data.data){
                        this.form.floor=res.data.data[0].floor
                        this.form.unit=res.data.data[0].unit

                    }else {

                    }
                    this.bed=res.data.data

                })
            },
            save(){


                this.$refs['form'].validate(async (valid) => {
                    console.log(this.value3)
                    let obj = {};
                    obj = this.room.find((item)=>{
                        return item.id === this.value3;

                    });

                    let getName = ''
                    getName = obj.roomCode;
                    this.form.unit=obj.unit
                    this.form.floor=obj.floor
                    this.form.buildingNumber= this.value2
                    this.form.roomNumber= getName
                    this.form.bedNumber=this.value4
                    // this.form.elderlyBirth= this.elderlyBirth
                    this.form.elderlyGender=this.radio
                    // this.form.plannedCheckInTime= this.plannedCheckInTime
                    this.form.relationship=this.relationship
                    if (valid) {
                        if(this.id>0){
                           console.log(this.form)
                            const {code,data} = await revise(this.form);
                            console.log(data)
                            if(code==200){
                                this.$message({
                                    message: "修改成功",
                                    type: 'success'
                                })
                                this.dialogFormVisible=false
                                this.search()
                            }else {

                            }
                        }else{




                            console.log(this.form)
                            const {code,data} = await add(this.form);
                                console.log(data)
                            if(code==200){
                                this.$message({
                                    message: "预定成功",
                                    type: 'success'
                                })

                                this.search()
                                this.dialogFormVisible=false

                            }else {

                            }



                        }




                    }
                    else {
                        return false;
                    }
                });

            },
            search(id,data){
                this.id = id
                this.listLoading = true;

                if(this.id==undefined){


                    this.queryForm.institutionNumber=this.form.institutionNumber
                }else {
                    console.log(this.formInline.institutionNumber)
                    this.queryForm.institutionNumber= this.formInline.institutionNumber

                }
              this.listLoading = true;
              // this.queryForm.institutionNumber=localStorage.getItem("institutionNumber")
              this.queryForm.elderlyName=this.organ.name
                search(this.queryForm).then(res =>{
                     console.log(res.data.total)
                     this.list=res.data.data
                     this.total=res.data.total
                  setTimeout(() => {
                    this.listLoading = false;
                  }, 500);
                   this.queryForm.currPageNo=1
                })
            },
            close(){
                this.dialogFormVisible=false
            }
        }
    }
</script>

<style  scoped>

.active >>> .el-table__body tr.current-row > td{
  background-color: #409eff !important
}
.active >>> .el-table__body tr.current-row > td .cell{
color: #ffffff !important
}
.active >>>.el-table__body tr:hover>td {
   background-color: #409eff !important;
      color: #ffffff;
 }
.el-header {
  background-color: #B3C0D1;
  color: #333;
  line-height: 30px;
}

.el-aside {
  color: #333;
}
</style>
